import axios from "axios";
import store from '../store/index';

let baseURL;
console.log(process.env.NODE_ENV)
if(process.env.NODE_ENV === 'development') {
    baseURL = 'http://gzquerytest.gzsunac.cn/api';
} else if(process.env.NODE_ENV === 'production') {
    baseURL = 'http://gzquery.sunacctg.com/api';
} else if (process.env.NODE_ENV === "test") {
	baseURL = 'http://gzquerytest.gzsunac.cn/api';
}
const http = axios.create({
  baseURL : baseURL,
  // headers : {
  // 	"Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",
  // 	'Accept' : 'application/json'
  // },
});
//添加请求拦截器
http.interceptors.request.use((config)=>{
    store.commit("setLoading",true);
    return config;
},(err)=>{
  alert("请求失败，请重试");
  store.commit("setLoading",false);
})
// 添加响应拦截器
http.interceptors.response.use(function (response) {
    store.commit("setLoading",false);
    return response.data;
}, function (error) {
    alert("请求失败，请重试");
    store.commit("setLoading",false);
    return Promise.reject(error);
});
export default http;
